import axios from 'axios'

const service = axios.create({
    baseURL: process.env.VUE_APP_DOOR_CONTROL,
    timeout: 3000,
})

service.interceptors.request.use(config => {
    if(/get/i.test(config.method)) {
        config.params = config.params || {}
        config.params.t = Date.parse(new Date())
    }
    return config
})

export function openDoor(password) {
    return service({
        url: "OpenDoor",
        method: 'get',
        params: password
    })
}

export function inputPassWord(single_pass) {
    return service({
        url: "Input",
        method: 'get',
        params: single_pass
    })
}

export function delPassWord() {
    return service({
        url: "Del",
        method: 'get'
    })
}

export function changePassWord(password) {
    return service({
        url: "Change",
        method: "get",
        params: password
    })
}

export function closeDoor() {
    return service({
        url: "CloseDoor",
        method: "get"
    })
}
